// $Id: EditPluginSettings.cs 64 2008-05-06 18:29:47Z nvivo $

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DBLGen.UI;

namespace DBLGen.GUI.Forms
{
    public partial class EditPluginSettings : Form
    {
        private PluginInfo _pluginInfo;
        private PluginSettings _settings;
        private PluginSettingsEditor _editor;

        public EditPluginSettings(PluginInfo pluginInfo, PluginSettings settings)
        {
            if (pluginInfo == null)
                throw new ArgumentNullException("pluginInfo");

            InitializeComponent();
            
            _pluginInfo = pluginInfo;

            this.Text = _pluginInfo.Name + " Settings";

            if (settings != null)
                _settings = settings.Clone();
        }

        public PluginSettings Settings
        {
            get
            {
                if (_settings == null)
                    _settings = _pluginInfo.CreateSettings();

                return _settings;
            }
        }

        private void EditPluginSettings_Load(object sender, EventArgs e)
        {
            _editor = _pluginInfo.CreateEditor();

            _editor.LoadSettings(Settings);
            _editor.Location = new Point(8, 8);

            this.Size = new Size(_editor.Width + 24, _editor.Height + 80);
            this.Controls.Add(_editor);
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            _settings = _editor.SaveSettings();
            Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            Close();
        }

    }
}